// components/Back/back.js
const app = getApp(),
  {
    $resHost
  } = app.globalData;
Component({
  data: {
    show: false,
    backPng: `rgba(255,255,255,.6) url(${$resHost}/img/miniprogram/newDetail/back.png) no-repeat center / 18px`,
    homePng: `rgba(255,255,255,.6) url(${$resHost}/img/miniprogram/newDetail/home2.png) no-repeat center / 18px`,
    haveBack: true,
    urls: ['independentGoods/Goods/goods', 'independentNewGoods/Goods/index', 'independentLimitGoods/Goods/index', 'independentNewGoods/Combo/index', 'independentKill/Kill/Detail/detail', 'independentBargain/Bargain/Detail/detail', 'independentCollage/Collage/Detail/detail', 'independentCrowdFunding/CrowdFunding/Detail/detail', 'independentWishAssist/WishAssist/Detail/detail', 'independentPresell/Detail/index', 'pages/Employee/Material/caseDetail', 'pages/User/luckDraw/Detail/detail', 'pages/User/Activity/Info/info', 'pages/Employee/Activity/Info/info', 'pages/TabBar/House/detail', 'pages/Employee/videoList/videoDetails/details', 'pages/User/Vcard/vcard2', 'pages/Employee/Vcard/vcard', 'pages/Employee/Me/meSetting', 'pages/Employee/Home/home', 'pages/User/Spread/account', 'pages/Employee/openActivity/user', 'pages/Employee/openActivity/employee', 'pages/Employee/openActivity/index', 'pages/Employee/distribution/home/partner']
  },
  methods: {
    back() {
      if (this.data.haveBack) {
        xhs.navigateBack();
      } else {
        xhs.reLaunch({
          url: '/pages/Engine/engine'
        });
      }
    }
  },
  lifetimes: {
    attached() {
      const pages = getCurrentPages();
      const haveBack = pages.length !== 1;
      const show = this.data.urls.includes(pages.pop().route);
      if (show) {
        this.setData({
          top: xhs.getMenuButtonBoundingClientRect().top,
          haveBack,
          show
        });
      }
    }
  }
});